<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>effect</title>
</head>
<body>
    <div id="test"></div>
    <script>
        let obj = {text: '大伟聊前端'};

        const bucket = new Set();

        const newObj = new Proxy(obj, {
            get(target, key) {
                bucket.add(effect);
                return target[key];
            },
            set(target, key, newVal) {
                target[key] = newVal;
                bucket.forEach(fn => fn());
                return true;
            }
        });

        function effect () {
            document.getElementById('test').innerText= newObj.text;
        }
        effect();
        newObj.text = 'vue3';
        setTimeout(() => {
            newObj.text = 'vue2';
        }, 3000);

    </script>
</body>
</html>